<?php
class Acounts extends AsbtractRestController {

	public function __construct() {
		parent::__construct();
	}

	public function login_post() {
		$arr_resp = $this->checkUserAuth();		
		if (isset($arr_resp)) {
			return $this->response($arr_resp);
		}
		$account = $this->input->post('account');
		$this->load->Model("User");
		if ($account == 'admob') {
			$admobPassword = $this->input->post("admobPassword");
			if ($admobPassword) {
				$error_msg = $this->User->insertAdmobUserAcount($this->email,$admobPassword);
				if (isset($error_msg)) {
					return $this->response($this->constructErrorMsg(ErrorMessgaes::$USER_ACOUNT_ADMOB_CODE,$error_msg));
				} else {
					$this->session->set_userdata(array("admobPassword" => $admobPassword));
				}
			} else {
				return $this->response($this->constructErrorMsg(ErrorMessgaes::$USER_ACOUNT_ADMOB_CODE,ErrorMessgaes::$USER_ACOUNT_INVALID_ACOUNT_DETAILS_MSG));
			}
		} elseif ($account == 'chartboost') {
			$chartBoostUserId = $this->input->post("chartBoostUserId");
			$chartBoostUserSignature = $this->input->post("chartBoostUserSignature");
			if ($chartBoostUserId && $chartBoostUserSignature) {
				$error_msg = $this->User->insertChartboostUserAcount($this->email,$chartBoostUserId,$chartBoostUserSignature);
				if (isset($error_msg)) {
					return $this->response($this->constructErrorMsg(ErrorMessgaes::$USER_ACOUNT_CHARTBOOST_CODE,$error_msg));
				}
			} else {
				return $this->response($this->constructErrorMsg(ErrorMessgaes::$USER_ACOUNT_CHARTBOOST_CODE,ErrorMessgaes::$USER_ACOUNT_INVALID_ACOUNT_DETAILS_MSG));
			}
		} else {
			return $this->response($this->constructErrorMsg(ErrorMessgaes::$USER_ACOUNT_CODE,ErrorMessgaes::$USER_ACOUNT_INVALID_ACOUNT_MSG));
		}
	}

}